<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('菜品列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>菜品名称：</label>
                                <input type="text" name="dishName"/>
                            </li>
                            <li>
                                <label>菜品标题：</label>
                                <input type="text" name="dishTitle"/>
                            </li>
                            <li>
                                <label>菜品编码：</label>
                                <input type="text" name="dishCode"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="recipe:dish:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="recipe:dish:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="recipe:dish:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="recipe:dish:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()">
                    <i class="fa fa-upload"></i> 批量导入
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('recipe:dish:edit')}]];
        var removeFlag = [[${@permission.hasPermi('recipe:dish:remove')}]];
        var datas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "recipe/dish";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTmpl",
                sortName: "createTime desc, dishId",
                sortOrder: "desc",
                modalName: "菜品",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'dishId',
                    title: '菜品ID',
                    visible: false
                },
                {
                    field: 'dishName',
                    title: '菜品名称',
                    sortable: true
                },
                {
                    field: 'dishTitle',
                    title: '菜品标题',
                    sortable: true
                },
                {
                    field: 'dishContent',
                    title: '菜品描述'
                },
                {
                    field: 'dishPic',
                    title: '菜品图片',
                    formatter: function(value, row, index) {
                        // 图片预览（注意：如存储在本地直接获取数据库路径，如有配置context-path需要使用ctx+路径）
                        // 如：/profile/upload/2019/08/08/3b7a839aced67397bac694d77611ce72.png
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'likesCount',
                    title: '点赞数量',
                    sortable: true
                },
                {
                    field: 'dishSort',
                    title: '菜品顺序',
                    sortable: true
                },
                {
                    field: 'author',
                    title: '作者'
                },
                {
                    field: 'dishCode',
                    title: '菜品编码'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.dishId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.dishId + '\')"><i class="fa fa-remove"></i>删除</a>');

                        var more = [];
                        more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='itemManage(" + row.dishId + ")'><i class='fa fa-user'></i>材料管理</a>");
                        more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='stepManage(" + row.dishId + ")'><i class='fa fa-user'></i>步骤管理</a>");
                        more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='mealManage(" + row.dishId + ")'><i class='fa fa-user'></i>辅食管理</a>");
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /** 材料管理 */
        function itemManage(dishId) {
            var url = prefix + '/itemManage/' + dishId;
            $.modal.openTab("材料管理", url);
        }

        /** 步骤管理 */
        function stepManage(dishId) {
            var url = prefix + '/stepManage/' + dishId;
            $.modal.openTab("步骤管理", url);
        }

        /** 辅食管理 */
        function mealManage(dishId) {
            var url = prefix + '/mealManage/' + dishId;
            $.modal.openTab("辅食管理", url);
        }
    </script>

     <script id="importTpl" type="text/template">
         <form enctype="multipart/form-data" class="mt40 mb20">
             <div class="col-xs-offset-1">
                 <input type="file" id="file" name="file"/>
                 <div class="mt10 pt5">
                     <input type="checkbox" id="updateSupport" name="updateSupport" title="如果数据已经存在，更新这条数据。"> 是否更新已经存在的数据&nbsp;
                     <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
                 </div>
                 <font color="red" class="pull-left mt10">
                     提示：仅允许导入“xls”或“xlsx”格式文件！
                 </font>
             </div>
         </form>
     </script>
</body>
</html>